#ifndef __PLATFORM_H__
#define __PLATFORM_H__

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */
#include <pthread.h>
#include "hi_common.h"
#include "hi_buffer.h"
#include "hi_comm_sys.h"
#include "hi_comm_vb.h"
#include "hi_comm_isp.h"
#include "hi_comm_vi.h"
#include "hi_comm_vo.h"
#include "hi_comm_venc.h"
#include "hi_comm_vdec.h"
#include "hi_comm_vpss.h"
#include "hi_comm_region.h"
#include "hi_comm_adec.h"
#include "hi_comm_aenc.h"
#include "hi_comm_ai.h"
#include "hi_comm_ao.h"
#include "hi_comm_aio.h"
#include "hi_defines.h"
#include "hi_comm_hdmi.h"
#include "hi_mipi.h"
#include "hi_comm_vgs.h"
#include "hi_mipi_tx.h"
#include "mpi_sys.h"
#include "mpi_vb.h"
#include "mpi_vi.h"
#include "mpi_vo.h"
#include "mpi_venc.h"
#include "mpi_vdec.h"
#include "mpi_vpss.h"
#include "mpi_region.h"
#include "mpi_audio.h"
#include "mpi_isp.h"
#include "mpi_ae.h"
#include "mpi_awb.h"
#include "hi_math.h"
#include "hi_sns_ctrl.h"
#include "mpi_hdmi.h"
#include "mpi_vgs.h"
#include "hi_ive.h"
#include "mpi_ive.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/prctl.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <errno.h>
#include <math.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include "hifb.h"
//#include "loadbmp.h"
#include "hi_tde_api.h"
#include "hi_tde_type.h"
#include "hi_tde_errcode.h"
#include "hi_math.h"
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <stdio.h>
#include <mqueue.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include "hi_mipi_tx.h"
#define MIPI_DEV_NODE       "/dev/hi_mipi"
#define OS01A               0
#define OV426               1
#define OV9734              2
#define MAX_SENSOR_NUM      3
#define ISP_MAX_DEV_NUM     4
#define HDMI_1080P           1   //EDWIN
#define HDMI_1920x1200      2   //EDWIN


extern ISP_SNS_OBJ_S stSnsOs01aObj;
extern ISP_SNS_OBJ_S stSnsOv426Obj;
extern ISP_SNS_OBJ_S stSnsov9734Obj;

/*******************************************************
    macro define
*******************************************************/
#define FILE_NAME_LEN               128
#define CHECK_CHN_RET(express,Chn,name)\
    do{\
        HI_S32 Ret;\
        Ret = express;\
        if (HI_SUCCESS != Ret)\
        {\
            printf("\033[0;31m%s chn %d failed at %s: LINE: %d with %#x!\033[0;39m\n", name, Chn, __FUNCTION__, __LINE__, Ret);\
            fflush(stdout);\
            return Ret;\
        }\
    }while(0)

#define CHECK_RET(express,name)\
    do{\
        HI_S32 Ret;\
        Ret = express;\
        if (HI_SUCCESS != Ret)\
        {\
            printf("\033[0;31m%s failed at %s: LINE: %d with %#x!\033[0;39m\n", name, __FUNCTION__, __LINE__, Ret);\
            return Ret;\
        }\
    }while(0)
#define SAMPLE_PIXEL_FORMAT         PIXEL_FORMAT_YVU_SEMIPLANAR_420

#define COLOR_RGB_RED      0xFF0000
#define COLOR_RGB_GREEN    0x00FF00
#define COLOR_RGB_BLUE     0x0000FF
#define COLOR_RGB_BLACK    0x000000
#define COLOR_RGB_YELLOW   0xFFFF00
#define COLOR_RGB_CYN      0x00ffff
#define COLOR_RGB_WHITE    0xffffff

#define SAMPLE_VO_DEV_DHD0 0                        /* VO's device HD0 */
#define SAMPLE_VO_DEV_DHD1 1                        /* VO's device HD1 */
#define SAMPLE_VO_DEV_UHD  SAMPLE_VO_DEV_DHD0       /* VO's ultra HD device:HD0 */
#define SAMPLE_VO_DEV_HD   SAMPLE_VO_DEV_DHD1       /* VO's HD device:HD1 */
#define SAMPLE_VO_LAYER_VHD0 0
#define SAMPLE_VO_LAYER_VHD1 1
#define SAMPLE_VO_LAYER_VHD2 2
#define SAMPLE_VO_LAYER_PIP  SAMPLE_VO_LAYER_VHD2

#define SAMPLE_AUDIO_EXTERN_AI_DEV 0
#define SAMPLE_AUDIO_EXTERN_AO_DEV 0
#define SAMPLE_AUDIO_INNER_AI_DEV 0
#define SAMPLE_AUDIO_INNER_AO_DEV 0
#define SAMPLE_AUDIO_INNER_HDMI_AO_DEV 1

#define SAMPLE_AUDIO_PTNUMPERFRM   480

#define WDR_MAX_PIPE_NUM        4
#define SAMPLE_PRT(fmt...)   \
    do {\
        printf("[%s]-%d: ", __FUNCTION__, __LINE__);\
        printf(fmt);\
    }while(0)
#define HIFB_RED_1555          0xFC00
#define HIFB_RED_8888          0xFFFF0000

#define GRAPHICS_LAYER_G0      0
#define GRAPHICS_LAYER_G1      1
#define GRAPHICS_LAYER_G3      2
#define CAMER_WIDTH             400                     //OV426
#define CAMER_HEIGHT            400                     //OV426

#define DISPLAY_WIDTH           1320                    //触摸屏前面的1080像数宽度，后面200像素宽度为图标栏tool
#define FACTORY_DISPLAY_WIDTH   800                     //触摸屏中间的800像数宽度

#define SCREEN_WIDTH            1920                    //屏的宽度像素
#define SCREEN_HEIGHT           1080                    //屏的高度像素
#define BLANK_OFFSET            0                       //2

//=================================================================================================
//OSD图标叠加的位置宏

#define X_OFFSET                420

#define BATTERY_X               130
#define BATTERY_Y               10
#define BATTERY_WIDTH           48
#define BATTERY_HEIGHT          48

#define SD_X                    448
#define SD_Y                    10
#define SD_WIDTH                48
#define SD_HEIGHT               48

#define FREEZE_X                600
#define FREEZE_Y                10
#define FREEZE_WIDTH            48
#define FREEZE_HEIGHT           48

#define PHOTO_X                 696
#define PHOTO_Y                 10
#define PHOTO_WIDTH             48
#define PHOTO_HEIGHT            48

#define PHOTO_F_X               180
#define PHOTO_F_Y               10
#define PHOTO_F_WIDTH           48
#define PHOTO_F_HEIGHT          48

#define RECORD_X                648
#define RECORD_Y                10
#define RECORD_WIDTH            48
#define RECORD_HEIGHT           48

#define LED_X                   496
#define LED_Y                   10
#define LED_WIDTH               48
#define LED_HEIGHT              48

#define LED_LEVEL_X             544
#define LED_LEVEL_Y             20

#define TIME_WIDTH              24
#define TIME_HEIGHT             32

#define MONTH1_X                350//230
#define MONTH1_Y                10
#define MONTH2_X                374//254
#define MONTH2_Y                10

#define UNDER_X                 398//278
#define UNDER_Y                 10

#define DAY1_X                  422//302
#define DAY1_Y                  10
#define DAY2_X                  446//326
#define DAY2_Y                  10

#define HOUR1_X                 480//360
#define HOUR1_Y                 10
#define HOUR2_X                 504//384
#define HOUR2_Y                 10

#define DOT1_X                  528//408
#define DOT1_Y                  10

#define MIN1_X                  552//432
#define MIN1_Y                  10
#define MIN2_X                  576//456
#define MIN2_Y                  10

#define DOT2_X                  600//480
#define DOT2_Y                  10

#define SEC1_X                  624//504
#define SEC1_Y                  10
#define SEC2_X                  648//528
#define SEC2_Y                  10

#define PARAM_NO_EXIST_PARAM   -565758
    
//=================================================================================================
//图像参数配置文件的路径
#define PARAM_FILE              "/etc/watermask/para.ini"
#define DEFAULT_PARAM_FILE      "/etc/watermask/default_para.ini"
//=================================================================================================
//    enum define
//=================================================================================================

typedef enum hiPIC_SIZE_E
{
    PIC_CIF,
    PIC_360P,      /* 640 * 360 */
    PIC_D1_PAL,    /* 720 * 576 */
    PIC_D1_NTSC,   /* 720 * 480 */
    PIC_720P,      /* 1280 * 720  */
    PIC_1080P,     /* 1920 * 1080 */
    PIC_2592x1520,
    PIC_2592x1536,
    PIC_2592x1944,
    PIC_2688x1536,
    PIC_2716x1524,
    PIC_3840x2160,
    PIC_4096x2160,
    PIC_3000x3000,
    PIC_4000x3000,
    PIC_7680x4320,
    PIC_3840x8640,
    PIC_800x800,
    PIC_400x400,
    PIC_BUTT
} PIC_SIZE_E;

typedef enum hiSAMPLE_SNS_TYPE_E
{
    OMNIVISION_OS01A_MIPI_4M_30FPS_10BIT,
    OMNIVISION_OV426_MIPI_4M_30FPS_10BIT,
    OMNIVISION_OV9734_MIPI_4M_30FPS_10BIT,
    SAMPLE_SNS_TYPE_BUTT,
} SAMPLE_SNS_TYPE_E;


typedef enum hiSAMPLE_VO_MODE_E
{
    VO_MODE_1MUX  ,
    VO_MODE_2MUX  ,
    VO_MODE_4MUX  ,
    VO_MODE_8MUX  ,
    VO_MODE_9MUX  ,
    VO_MODE_16MUX ,
    VO_MODE_25MUX ,
    VO_MODE_36MUX ,
    VO_MODE_49MUX ,
    VO_MODE_64MUX ,
    VO_MODE_2X4   ,
    VO_MODE_BUTT
} SAMPLE_VO_MODE_E;

typedef enum hiSAMPLE_RC_E
{
    SAMPLE_RC_CBR = 0,
    SAMPLE_RC_VBR,
    SAMPLE_RC_AVBR,
    SAMPLE_RC_QVBR,
    SAMPLE_RC_CVBR,
    SAMPLE_RC_QPMAP,
    SAMPLE_RC_FIXQP
} SAMPLE_RC_E;


/*******************************************************
    structure define
*******************************************************/
typedef struct hiSAMPLE_VENC_QPMAP_SENDFRAME_PARA_S
{
    HI_BOOL  bThreadStart;
    VPSS_GRP VpssGrp;
    VPSS_CHN VpssChn;
    VENC_CHN VeChn[VENC_MAX_CHN_NUM];
    HI_S32   s32Cnt;
    SIZE_S   stSize;
} SAMPLE_VENC_QPMAP_SENDFRAME_PARA_S;


typedef struct hiSAMPLE_VI_DUMP_THREAD_INFO_S
{
    VI_PIPE     ViPipe;
    HI_S32      s32Cnt;
    HI_BOOL     bDump;
    HI_CHAR     aszName[128];
    pthread_t   ThreadId;
} SAMPLE_VI_DUMP_THREAD_INFO_S;

typedef struct hiSAMPLE_SENSOR_INFO_S
{
    SAMPLE_SNS_TYPE_E   enSnsType;
    HI_S32              s32SnsId;
    HI_S32              s32BusId;
    combo_dev_t           MipiDev;
} SAMPLE_SENSOR_INFO_S;

typedef struct hiSAMPLE_SNAP_INFO_S
{
    HI_BOOL  bSnap;
    HI_BOOL  bDoublePipe;
    VI_PIPE    VideoPipe;
    VI_PIPE    SnapPipe;
    VI_VPSS_MODE_E  enVideoPipeMode;
    VI_VPSS_MODE_E  enSnapPipeMode;
}SAMPLE_SNAP_INFO_S;

typedef struct hiSAMPLE_DEV_INFO_S
{
    VI_DEV      ViDev;
    WDR_MODE_E  enWDRMode;
} SAMPLE_DEV_INFO_S;

typedef struct hiSAMPLE_PIPE_INFO_S
{
    VI_PIPE         aPipe[WDR_MAX_PIPE_NUM];
    VI_VPSS_MODE_E  enMastPipeMode;
    HI_BOOL         bMultiPipe;
    HI_BOOL         bVcNumCfged;
    HI_BOOL         bIspBypass;
    PIXEL_FORMAT_E  enPixFmt;
    HI_U32          u32VCNum[WDR_MAX_PIPE_NUM];
} SAMPLE_PIPE_INFO_S;

typedef struct hiSAMPLE_CHN_INFO_S
{
    VI_CHN              ViChn;
    PIXEL_FORMAT_E      enPixFormat;
    DYNAMIC_RANGE_E     enDynamicRange;
    VIDEO_FORMAT_E      enVideoFormat;
    COMPRESS_MODE_E     enCompressMode;
} SAMPLE_CHN_INFO_S;

typedef struct hiSAMPLE_VI_INFO_S
{
    SAMPLE_SENSOR_INFO_S    stSnsInfo;
    SAMPLE_DEV_INFO_S       stDevInfo;
    SAMPLE_PIPE_INFO_S      stPipeInfo;
    SAMPLE_CHN_INFO_S       stChnInfo;
    SAMPLE_SNAP_INFO_S      stSnapInfo;
} SAMPLE_VI_INFO_S;

typedef struct hiSAMPLE_VI_CONFIG_S
{
    SAMPLE_VI_INFO_S    astViInfo[VI_MAX_DEV_NUM];
    HI_S32              as32WorkingViId[VI_MAX_DEV_NUM];
    HI_S32              s32WorkingViNum;
} SAMPLE_VI_CONFIG_S;

typedef struct hiSAMPLE_VI_FRAME_CONFIG_S
{
    HI_U32                  u32Width;
    HI_U32                  u32Height;
    HI_U32                  u32ByteAlign;
    PIXEL_FORMAT_E          enPixelFormat;
    VIDEO_FORMAT_E          enVideoFormat;
    COMPRESS_MODE_E         enCompressMode;
    DYNAMIC_RANGE_E         enDynamicRange;
} SAMPLE_VI_FRAME_CONFIG_S;

typedef struct hiSAMPLE_VI_FRAME_INFO_S
{
    VB_BLK             VbBlk;
    HI_U32             u32Size;
    VIDEO_FRAME_INFO_S stVideoFrameInfo;
} SAMPLE_VI_FRAME_INFO_S;

typedef struct hiSAMPLE_VI_FPN_CALIBRATE_INFO_S
{
    HI_U32                  u32Threshold;
    HI_U32                  u32FrameNum;
    ISP_FPN_TYPE_E          enFpnType;
    PIXEL_FORMAT_E          enPixelFormat;
    COMPRESS_MODE_E         enCompressMode;
} SAMPLE_VI_FPN_CALIBRATE_INFO_S;

typedef struct hiSAMPLE_VI_FPN_CORRECTION_INFO_S
{
    ISP_OP_TYPE_E           enOpType;
    ISP_FPN_TYPE_E          enFpnType;
    HI_U32                  u32Strength;
    PIXEL_FORMAT_E          enPixelFormat;
    COMPRESS_MODE_E         enCompressMode;
    SAMPLE_VI_FRAME_INFO_S  stViFrameInfo;
} SAMPLE_VI_FPN_CORRECTION_INFO_S;

typedef struct tag_SAMPLE_VO_WBC_CONFIG
{
    VO_WBC_SOURCE_TYPE_E    enSourceType;
    DYNAMIC_RANGE_E         enDynamicRange;
    COMPRESS_MODE_E         enCompressMode;
    HI_S32 s32Depth;

    HI_S32                  VoWbc;
    VO_WBC_ATTR_S           stWbcAttr;
    VO_WBC_SOURCE_S         stWbcSource;
    VO_WBC_MODE_E           enWbcMode;

}SAMPLE_VO_WBC_CONFIG;

typedef struct hiSAMPLE_COMM_VO_LAYER_CONFIG_S
{
    /* for layer */
    VO_LAYER                VoLayer;
    VO_INTF_SYNC_E          enIntfSync;
    RECT_S                  stDispRect;
    SIZE_S                  stImageSize;
    PIXEL_FORMAT_E          enPixFormat;

    HI_U32                  u32DisBufLen;
    DYNAMIC_RANGE_E         enDstDynamicRange;

    /* for chn */
    SAMPLE_VO_MODE_E        enVoMode;
}SAMPLE_COMM_VO_LAYER_CONFIG_S;

typedef struct hiSAMPLE_VO_CONFIG_S
{
    /* for device */
    VO_DEV                  VoDev;
    VO_INTF_TYPE_E          enVoIntfType;
    VO_INTF_SYNC_E          enIntfSync;
    PIC_SIZE_E              enPicSize;
    HI_U32                  u32BgColor;

    /* for layer */
    PIXEL_FORMAT_E          enPixFormat;
    RECT_S                  stDispRect;
    SIZE_S                  stImageSize;
    VO_PART_MODE_E          enVoPartMode;

    HI_U32                  u32DisBufLen;
    DYNAMIC_RANGE_E         enDstDynamicRange;

    /* for chnnel */
    SAMPLE_VO_MODE_E        enVoMode;
} SAMPLE_VO_CONFIG_S;


typedef enum hiTHREAD_CONTRL_E
{
    THREAD_CTRL_START,
    THREAD_CTRL_PAUSE,
    THREAD_CTRL_STOP,
}THREAD_CONTRL_E;

typedef struct hiVDEC_THREAD_PARAM_S
{
    HI_S32 s32ChnId;
    PAYLOAD_TYPE_E enType;
    HI_CHAR cFilePath[128];
    HI_CHAR cFileName[128];
    HI_S32 s32StreamMode;
    HI_S32 s32MilliSec;
    HI_S32 s32MinBufSize;
    HI_S32 s32IntervalTime;
    THREAD_CONTRL_E eThreadCtrl;
    HI_U64  u64PtsInit;
    HI_U64  u64PtsIncrease;
    HI_BOOL bCircleSend;
}VDEC_THREAD_PARAM_S;

typedef struct hiSAMPLE_VDEC_BUF
{
    HI_U32  u32PicBufSize;
    HI_U32  u32TmvBufSize;
    HI_BOOL bPicBufAlloc;
    HI_BOOL bTmvBufAlloc;
}SAMPLE_VDEC_BUF;


typedef struct hiSAMPLE_VDEC_VIDEO_ATTR
{
    VIDEO_DEC_MODE_E enDecMode;
    HI_U32              u32RefFrameNum;
    DATA_BITWIDTH_E  enBitWidth;
}SAMPLE_VDEC_VIDEO_ATTR;

typedef struct hiSAMPLE_VDEC_PICTURE_ATTR
{
    PIXEL_FORMAT_E enPixelFormat;
    HI_U32         u32Alpha;
}SAMPLE_VDEC_PICTURE_ATTR;


typedef struct hiSAMPLE_VDEC_ATTR
{
    PAYLOAD_TYPE_E enType;
    VIDEO_MODE_E   enMode;
    HI_U32 u32Width;
    HI_U32 u32Height;
    HI_U32 u32FrameBufCnt;
    HI_U32 u32DisplayFrameNum;
    union
    {
        SAMPLE_VDEC_VIDEO_ATTR stSapmleVdecVideo;      /* structure with video ( h265/h264) */
        SAMPLE_VDEC_PICTURE_ATTR stSapmleVdecPicture; /* structure with picture (jpeg/mjpeg )*/
    };
}SAMPLE_VDEC_ATTR;

typedef struct hiSAMPLE_VB_BASE_INFO_S
{
    PIXEL_FORMAT_E      enPixelFormat;
    HI_U32              u32Width;
    HI_U32              u32Height;
    HI_U32              u32Align;
    COMPRESS_MODE_E     enCompressMode;
}SAMPLE_VB_BASE_INFO_S;

typedef struct hiSAMPLE_VB_CAL_CONFIG_S
{
    HI_U32 u32VBSize;

    HI_U32 u32HeadStride;
    HI_U32 u32HeadSize;
    HI_U32 u32HeadYSize;

    HI_U32 u32MainStride;
    HI_U32 u32MainSize;
    HI_U32 u32MainYSize;

    HI_U32 u32ExtStride;
    HI_U32 u32ExtYSize;
}SAMPLE_VB_CAL_CONFIG_S;
typedef struct lcd_resoluton {
	HI_U32 pu32W;
	HI_U32 pu32H;
	HI_U32 pu32Frm;
} lcd_resoluton_t;
typedef enum hiOSD_COLOR_FMT_E
{
    OSD_COLOR_FMT_RGB444    = 0,
    OSD_COLOR_FMT_RGB4444   = 1,
    OSD_COLOR_FMT_RGB555    = 2,
    OSD_COLOR_FMT_RGB565    = 3,
    OSD_COLOR_FMT_RGB1555   = 4,
    OSD_COLOR_FMT_RGB888    = 6,
    OSD_COLOR_FMT_RGB8888   = 7,
    OSD_COLOR_FMT_BUTT
} OSD_COLOR_FMT_E;
typedef struct tag_OSD_BITMAPINFOHEADER
{
    HI_U16      biSize;
    HI_U32       biWidth;
    HI_S32       biHeight;
    HI_U16       biPlanes;
    HI_U16       biBitCount;
    HI_U32      biCompression;
    HI_U32      biSizeImage;
    HI_U32       biXPelsPerMeter;
    HI_U32       biYPelsPerMeter;
    HI_U32      biClrUsed;
    HI_U32      biClrImportant;
} OSD_BITMAPINFOHEADER;
typedef struct tag_OSD_RGBQUAD
{
    HI_U8    rgbBlue;
    HI_U8    rgbGreen;
    HI_U8    rgbRed;
    HI_U8    rgbReserved;
} OSD_RGBQUAD;
typedef struct tag_OSD_Logo
{
    HI_U32    width;        /* out */
    HI_U32    height;       /* out */
    HI_U32    stride;       /* in */
    HI_U8*    pRGBBuffer;   /* in/out */
} OSD_LOGO_T;
typedef struct hiOSD_COMPONENT_INFO_S
{
    int alen;
    int rlen;
    int glen;
    int blen;
} OSD_COMP_INFO;


typedef struct hiOSD_SURFACE_S
{
    OSD_COLOR_FMT_E enColorFmt;         /* color format */
    HI_U8*  pu8PhyAddr;               /* physical address */
    HI_U16  u16Height;                /* operation height */
    HI_U16  u16Width;                 /* operation width */
    HI_U16  u16Stride;                /* surface stride */
    HI_U16  u16Reserved;
} OSD_SURFACE_S;

typedef struct tag_OSD_BITMAPFILEHEADER
{
    HI_U32   bfSize;
    HI_U16    bfReserved1;
    HI_U16    bfReserved2;
    HI_U32   bfOffBits;
} OSD_BITMAPFILEHEADER;
typedef struct tag_OSD_BITMAPINFO
{
    OSD_BITMAPINFOHEADER    bmiHeader;
    OSD_RGBQUAD                 bmiColors[1];
} OSD_BITMAPINFO;

typedef struct hiPTHREAD_HIFB_SAMPLE
{
    HI_S32           fd;          /* fb's file describ */
    HI_S32           layer;       /* which graphic layer */
    HI_S32           ctrlkey;     /* {0,1,2,3}={1buffer, 2buffer, 0buffer pan display, 0buffer refresh} */
    HI_BOOL          bCompress;   /* image compressed or not */
    HIFB_COLOR_FMT_E enColorFmt;  /* color format. */
} PTHREAD_HIFB_SAMPLE_INFO;
typedef struct hiSAMPLE_VENC_GETSTREAM_PARA_S
{
    HI_BOOL bThreadStart;
    VENC_CHN VeChn[VENC_MAX_CHN_NUM];
    HI_S32 s32Cnt;
    char path[50];
    int width;
    int height;
} SAMPLE_VENC_GETSTREAM_PARA_S;
extern VPSS_CHN VpssChn;
extern SAMPLE_VI_CONFIG_S stViConfig;
extern SAMPLE_VO_CONFIG_S stVoConfig;
extern combo_dev_cfg_t *g_mipi_tx_config;
extern VO_SYNC_INFO_S *g_mipi_tx_sync_info;
extern VO_USER_INTFSYNC_INFO_S * g_mipi_tx_user_intfsync_info;
extern lcd_resoluton_t * g_mipi_tx_lcd_resolution;
extern HI_VOID (*g_mipi_lcd_init)(HI_S32 s32fd);

/*
extern HI_CHAR *PATH_BAT[7];
extern HI_CHAR *PATH_SD[2];
extern HI_CHAR *PATH_PHOTO;
extern HI_CHAR *PATH_TIME[12];
extern HI_CHAR *PATH_BAT_OV426[7];
extern HI_CHAR *PATH_SD_OV426[2];
extern HI_CHAR *PATH_PHOTO_OV426;
extern HI_CHAR *PATH_TIME_OV426[12];
*/
//ADD BY EDWIN FOR 10INCH-PAD-------------------
extern HI_CHAR *PATH_FREEZE_10INCH;
extern HI_CHAR *PATH_PHOTOS_10INCH;
extern HI_CHAR *PATH_RECORD_10INCH;
extern HI_CHAR *PATH_LIGHTS_10INCH;
extern HI_CHAR *PATH_SDCARD_10INCH[2];
extern HI_CHAR *PATH_POWERS_10INCH[7];
extern HI_CHAR *PATH_TIME_10INCH[12];
//--------------------------------------------------

extern RGN_HANDLE MinHadle[16];
extern VGS_ADD_OSD_S astVgsAddOsd[16];
extern unsigned char *fbp;
extern unsigned char osdBufHdmi[1920*1080*4];
extern unsigned char ucguiBuf[1920*1080*4];                 //UC_GUI  BUFFER
extern int hdmi_disp_mode;                                  //EDWIN
extern int rc_mask_type;
extern int hdmi_size;

extern int copyefile;                                       //1=U盘拷贝状态,0=非拷贝状态:   定义在platform.c
extern int photo;                                           //1=拍照状态,0=非拍照状态：     定义在camera_thread.c
extern int video_freeze_state;                              //1=冻结状态,0=非冻结状态:     定义在platform.c
extern int record;                                          //1=录像状态,0=非录像状态:     定义在platform.c
extern int nosignal;                                        //1=无信号状态,0=有信号状态:    定义在platform.c
extern int MWB_State;                                       //1=白平衡状态,0=非白平衡状态;  定义在platform.c

HI_S32 SAMPLE_COMM_VI_StartVi(SAMPLE_VI_CONFIG_S* pstViConfig);
HI_S32 SAMPLE_COMM_VI_StopVi(SAMPLE_VI_CONFIG_S* pstViConfig);
HI_S32 SAMPLE_COMM_VO_StartVO(SAMPLE_VO_CONFIG_S *pstVoConfig);
HI_S32 SAMPLE_COMM_VO_StopVO(SAMPLE_VO_CONFIG_S *pstVoConfig);
HI_S32 SAMPLE_COMM_VENC_Start(PAYLOAD_TYPE_E enType,SIZE_S stSize,HI_U32 u32FrameRate,VPSS_CHN VpssChn,VENC_CHN VencChn,HI_U32 u32Profile, HI_BOOL bRcnRefShareBuf,VENC_GOP_ATTR_S *pstGopAttr,char *path);
HI_S32 SAMPLE_COMM_VENC_Stop(VPSS_CHN VpssChn);
HI_VOID SAMPLE_COMM_VDEC_StartSendStream(HI_S32 s32ChnNum, VDEC_THREAD_PARAM_S *pstVdecSend, pthread_t *pVdecThread);
HI_VOID SAMPLE_COMM_VDEC_CmdCtrl(HI_S32 s32ChnNum,VDEC_THREAD_PARAM_S *pstVdecSend, pthread_t *pVdecThread);
HI_VOID SAMPLE_COMM_VDEC_StopSendStream(HI_S32 s32ChnNum, VDEC_THREAD_PARAM_S *pstVdecSend, pthread_t *pVdecThread);
HI_S32 configViInit(HI_U32 u32ViIntfType);
HI_S32 configVoInit(HI_U32 u32VoIntfType);
HI_S32 configInit(HI_U32 u32ViIntfType,HI_U32 u32VoIntfType);
HI_S32 sysInit();
HI_S32 viVpssInit(SAMPLE_VI_CONFIG_S stViConfig,int disWidth,int disHeight);
HI_S32 viVpssDeinit();
HI_S32 vdencVpssInit(int disWidth,int disHeight);
HI_S32 vdencVpssDeinit();
int mppOsdCreate(int x,int y,int width,int height,RGN_HANDLE handle1,RGN_HANDLE handle2,HI_CHAR* PIC);
HI_S32 mppOsdCreate2(int x,int y,int width,int height,RGN_HANDLE handle,HI_CHAR* PIC,VGS_ADD_OSD_S *pstVgsAddOsd);
int mppOsdInfoUpdate();
int mppFrameGet(int vpssChn,int vpssGrp,VIDEO_FRAME_INFO_S *pstFrameInfom);
int mppFramePut(int vpssChn,int vpssGrp,int photo,VIDEO_FRAME_INFO_S *pstFrameInfom);
int mppFrameIveGetSrc(VIDEO_FRAME_INFO_S *pstFrameInfom,IVE_SRC_IMAGE_S *pstSrcImg);
int mppFrameYUV2RGB(VIDEO_FRAME_INFO_S *pstFrameInfom,IVE_SRC_IMAGE_S *pstSrcImg,IVE_SRC_IMAGE_S *pstDstImg);
int mppFrameRGB2YUV(VIDEO_FRAME_INFO_S *pstFrameInfom,IVE_SRC_IMAGE_S *pstSrcImg,IVE_SRC_IMAGE_S *pstDstImg);
int mppFrameCopy(IVE_SRC_IMAGE_S *pstSrcImg,IVE_SRC_IMAGE_S *pstDstImg);
int mppFrameFree(IVE_SRC_IMAGE_S *pstImg);
void initBattery();
int getBattery();
void mppClean(int mode,unsigned char *fbp,int immediate);


//=================================================================================================================================
//isp

void mppIsp_BLC(HI_S32 ViPipe, SAMPLE_VI_INFO_S* pstViInfo);

int ReadCfgFile(char *CfgFile, char *key, char * value, int *valueLen);
void mppisp_VO_VideoLayerCSC(HI_S32 type,HI_U32 value);
void mppisp_VO_GraphicLayerCSC(VO_LAYER VoLayer,HI_S32 type,HI_U32 value);
void mppIspAeManual(HI_S32 ViPipe,HI_S32 mode,HI_U8 op_type,HI_S32 data);

void mppIsp_AUTO_EXPOSURE(VI_PIPE ViPipe,HI_S32 mode);
//=======================================================================================================
//设置 AE 曝光分配策略,   AEtime-->AEgain HIS 3516dv300 isp
//=======================================================================================================
void mppisp_SetAERouteAttr();
//=======================================================================================================
//设置 AE 曝光分配扩展属性策略,   AEtime-->AEgain ;camera isp
//=======================================================================================================


void mppisp_dvp_ctrl();
void mppisp_mipi_ctrl();

void mppisp_SetAERouteAttrEx();

void mppIspAEDisable();
void mppIspCscManual(HI_S32 Vipipe,HI_S32 type,HI_U8 v);
void mppIspAwb(HI_S32 ViPipe,HI_U8 mode,HI_U16 u16ColorTemp,HI_U16 Rgain,HI_U16 Grgain,HI_U16 Gbgain,HI_U16 Bgain);
void mppIspSharpen(HI_S32 ViPipe,HI_U8 mode,HI_U16 TextureFreq,HI_U16 EdgeFreq,HI_U8 Overshoot,HI_U8 UnderShoot,
            HI_U8 umax,HI_U8 umin,HI_U8 vmax,HI_U8 vmin,HI_U8 luma,HI_U16 texturestr,HI_U16 edgestr,HI_U8 supstr,
            HI_U8 supadj,HI_U8 detailctrl,HI_U8 detailctrlthr,HI_U8 edgefilt,HI_U8 rgain,HI_U8 ggain,HI_U8 bgain,
            HI_U8 skingain,HI_U16 maxsharp);

void mppIspDeCtrl(HI_S32 ViPipe,int enable, int mode,HI_U8 GlobaGain,HI_U8 GainLF,HI_U8 GainHF);
void mppIspLdciCtrl(HI_S32 ViPipe,int enable,int mode,int LPFSigma,int Blc,int pos_mean,int pos_sigma,int pos_wgt,
                                                       int neg_mean,int neg_sigma,int neg_wgt);

void mppIspGammaCtrl(HI_S32 ViPipe,HI_U8 disable,HI_U8 mode);
void mppIspCcmCtrl(HI_S32 ViPipe,HI_U8 mode,HI_U16 *pu16matrix);
void mppIspHlcCtrl(HI_S32 ViPipe,HI_U8 mode,HI_U8 thr,HI_U8 tar);
HI_S32 mppChangeVo(SAMPLE_VO_CONFIG_S *pstVoConfig,int mode);
HI_S32 mppDisplayResize(SAMPLE_VI_CONFIG_S stViConfig,SAMPLE_VO_CONFIG_S stVoConfig,int disWidth,int disHeight);
HI_U32 mppAwbCalibration(HI_S32 ViPipe,HI_U32 u32Mode,ISP_AWB_Calibration_Gain_S *pstAWBCalibGain);
void mppIspNrCtrl(HI_S32 ViPipe,int enable,int mode,int chroma,int fine,int coring,int coar);
void mppIspCCMCtrl(HI_S32 ViPipe,int mode1,int mode2,int saturation,int rr,int rg,int rb,int gr,int gg,int gb,int br,int bg,int bb);
//void mppIsp3DNRCtrl(HI_S32 ViPipe,int ies,int iedz);
void mppIsp3DNRCtrl(HI_S32 ViPipe, HI_U8 nr_level);
//=====================================================================================================================================

#define LOCAL_FILE_PIC_LOAD     ("/picture/")
#define LOCAL_FILE_AVI_LOAD     ("/video/")
#define SDCARD_DEV              ("/dev/mmcblk1")
#define SDCARD_FILE_PIC_LOAD    ("/sdcard/picture/")
#define SDCARD_FILE_AVI_LOAD    ("/sdcard/video/")
#define UDISK_DEV               ("/dev/mmcblk2")
#define UDISK_FILE_PIC_LOAD     ("/udisk/picture/")
#define UDISK_FILE_AVI_LOAD     ("/udisk/video/")

void mppOsdInit();
int myisspace(char *p, char *buf);
void RC_mask(unsigned char *buf,int mode);
void mppFrameRotate(int mode);
void mppFrameMirror(int mode);
void mppFrameScale();
void mppDisplaySet(int mode);
int file_exist(char *path);
int mkdirs(char *path);
void mppSensorChange(int sensor_dev);
//===========================================================================================================
//FPN
//===========================================================================================================
typedef struct st_fpn_attr
{
    SIZE_S              stPicSize;
    VB_BLK              VbBlk;
    VIDEO_FRAME_INFO_S  stVideoFrame;
    HI_U32              u32FrmSize;
    ISP_FPN_TYPE_E      enFpnType;
}FPN_ATTR_S;


HI_S32 FPN_init();
HI_S32 s32FPN_Calibrate(FPN_ATTR_S *pstFPNattr);
HI_S32 s32SaveFpnData(ISP_FPN_FRAME_INFO_S *pVBuf, FPN_ATTR_S *pstFPNattr);
HI_S32 s32ReadFpnData(ISP_FPN_FRAME_INFO_S *pVBuf, FPN_ATTR_S *pstFPNattr);
HI_S32 s32FPN_Correction(FPN_ATTR_S    *pstFPNattr);
HI_S32 s32GetVBFromPool(FPN_ATTR_S     *pstFPNattr);
HI_S32 s32ReleaseVBToPool(FPN_ATTR_S   *pstFPNattr);

char *GetIniKeyString(char *title,char *key,char *filename);
int GetIniKeyInt(char *title,char *key,char *filename);
int PutIniKeyString(char *title,char *key,char *val,char *filename);
int PutIniKeyInt(char *title,char *key,int val,char *filename);
int read_osd_parameter_key(char * id,char * idx,int default_value);

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */


#endif
